package de.eridea.learning.java.usermanagement.persistence;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "RESOURCES")
public class Resource {
	@Id
	@GeneratedValue
	private long id;

	@Column(nullable = false)
	private String idString;

	@ManyToMany
	@JoinTable(name = "PERMISSIONS", joinColumns = @JoinColumn(name = "Resource_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "Group_id", referencedColumnName = "id"))
	public Set<Group> groups = new HashSet<Group>();

	@ManyToOne
	private User owner;

	public long getId() {
		return id;
	}

	private void setId(long id) {
		this.id = id;
	}

	public String getIdString() {
		return idString;
	}

	public void setIdString(String idString) {
		this.idString = idString;
	}

	public User getOwner() {
		return owner;
	}

	public void setOwner(User owner) {
		this.owner = owner;
	}
}
